﻿using DG.Tweening;
using QFramework;
using UnityEngine;
using UnityEngine.Tilemaps;

namespace ProjectIndieFarm
{
    public class ToolHoe : ITool
    {
        public string Name => "hoe";

        public int Range => Global.PlantActionRange;

        public float TimeCost => Global.ToolHourCostHoe;

        public float ActionDuration => 0.5f* (Global.ToolHourCostHoe / Config.INIT_TOOL_HOUR_COST_HOE);

        public bool Selectable(ToolData data)
        {
            return Global.CurrentTool.Value.Name.Equals(Name)
                && data.SoilGrid[data.CellPosition.x, data.CellPosition.y] == null;
        }

        public void Use(ToolData data)
        {
            data.Tilemap.SetTile(new Vector3Int(data.CellPosition.x, data.CellPosition.y, 0), data.Pen);
            data.SoilGrid[data.CellPosition.x, data.CellPosition.y] = new SoilData();

            AudioController.Instance.SfxHoeDig.Play();

            var toolController = Object.FindObjectOfType<ToolController>();
            var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            toolController.DigFx.Position(mousePos.x, mousePos.y);
            toolController.DigFx.GetComponent<ParticleSystem>().Play();
            CameraController.ShakeHeavy();
        }
    }
}
